home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_dates2.arc / TEST.C < prev    next >
Text File  |  1991-01-10  |  2KB  |  83 lines

  1. /************************************************************************/
  2. /*  (c)  1988 by James N. Seed,  Atlanta, GA  -  all rights reserved.    */
  3. /*                                    */
  4. /*  This program is provided for example purposes only.  It, and/or    */
  5. /*  its executable equivalent, may not be sold or distributed in any    */
  6. /*  form for profit, without the prior written consent of the author.    */
  7. /*                                    */
  8. /************************************************************************/
  9. /*                                    */
  10. /*  The idea of this program is to test the C_dates conversion        */
  11. /*  functions, "gtoj" and "jtog", on EVERY date from January 1st, 0000    */
  12. /*  to December 31st, 9999. ( used it myself )                */
  13. /*                                    */
  14. /*            C_dates Initial release - errors show up    */
  15. /*            C_dates Version 2       - no errors        */
  16. /*                                    */
  17. /*  Note:  All other C_dates functions have always been error free.    */
  18. /************************************************************************/
  19.  
  20. #define     LINT_ARGS
  21.  
  22. #include "stdlib.h"
  23. #include "stdio.h"
  24. #include "c_dates.h"
  25.  
  26. static    char maxday[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  27.  
  28. static    char julerr[] = " - \areturned an invalid julian number.";
  29. static    char strerr[] = " - \acould not be converted properly.";
  30. static    char nxtdte[] = "\n           - checks out.";
  31. static    char currnt[] = "\r%02u/%02u/%04u";
  32. static    char aok[]    = "\r        All dates checked out - AOK !";
  33.  
  34. void _setargv()    { }
  35. void _setenvp()    { }
  36.  
  37. void main()
  38.  
  39. {
  40.     register unsigned month, day;
  41.  
  42.     unsigned year, chkdte[3], errjul = 0, errstr = 0;
  43.     unsigned long julian = 0;
  44.  
  45.     for ( printf( nxtdte ), year = 0; year < 10000; ++year )
  46.     {
  47.           for ( month = 1; month < 13; ++month )
  48.           {
  49.             if ( month == 2 )
  50.              maxday[ month ] = year % 4 ||
  51.                        ( !( year % 100 ) && year % 400 )
  52.                      ? 28 : 29;
  53.  
  54.             for ( day = 1; day <= maxday[ month ]; ++day )
  55.             {
  56.               printf( currnt, month, day, year );
  57.  
  58.               if ( gtoj( month, day, year ) != ++julian )
  59.               {
  60.                 ++errjul;
  61.                 printf( julerr ), printf( nxtdte );
  62.               }
  63.               else
  64.               {
  65.                 jtog( julian, (char *)chkdte, 0 );
  66.  
  67.                 if ( !( chkdte[0] == month &&
  68.                     chkdte[1] == day   &&
  69.                     chkdte[2] == year     ) )
  70.                 {
  71.                      ++errstr;
  72.                      printf( strerr ), printf( nxtdte );
  73.                 }
  74.               }
  75.             }
  76.           }
  77.     }
  78.  
  79.     if ( !errjul && !errstr ) printf( aok );
  80.  
  81.     exit( 0 );
  82. }
  83.